package com.zyy.service.combine;

import com.zyy.entity.Order;
import com.zyy.entity.User;
import com.zyy.entity.dto.Result;
import com.zyy.entity.dto.UserOrder;
import com.zyy.service.solo.OrderService;
import com.zyy.service.solo.UserService;
import org.simpleframework.core.annotation.Service;

/**
 * @Author: yu.zhou
 * @DateTime: 2023/01/03 14:22
 */
@Service
public class UserOrderService {

    private UserService userService;
    private OrderService orderService;

    public Result<UserOrder> getUserOrder(Long orderId) {
        // 获取数据
        Order order = orderService.queryOrderById(orderId);
        User user = userService.getUserById(order.getUserId());
        // 封装参数
        Result<UserOrder> result = mergeUserOrderResult(user, order);

        return result;
    }

    /**
     * 封装参数
     *
     * @param user
     * @param order
     * @return
     */
    private Result<UserOrder> mergeUserOrderResult(User user, Order order) {
        UserOrder userOrder = new UserOrder();
        userOrder.setId(order.getId());
        userOrder.setPrice(order.getPrice());
        userOrder.setName(order.getName());
        userOrder.setNum(order.getNum());
        userOrder.setUserId(order.getUserId());
        userOrder.setUsername(user.getUsername());
        return new Result<>();
    }

}
